package top.namelessman.springbootjsp.repository.impl;

import org.springframework.stereotype.Repository;
import top.namelessman.springbootjsp.entity.User;
import top.namelessman.springbootjsp.repository.UserRepository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;


@Repository
public class UserRepositoryImpl implements UserRepository {
    Map<Integer,User> list;
    public UserRepositoryImpl(){
        list = new HashMap<>();
        list.put(1,new User(1,"user1","111111"));
        list.put(2,new User(2,"user2","222222"));
        list.put(3,new User(3,"user3","333333"));
        list.put(4,new User(4,"user4","444444"));
    }

    @Override
    public User findById(Integer id) {
        return list.get(id);
    }

    @Override
    public Collection<User> findAll() {
        return list.values();
    }

    @Override
    public void save(User user) {
        list.put(user.getId(),user);
    }

    @Override
    public void deleteById(Integer id) {
        list.remove(id);
    }
}
